package cn.edu.neosoft.sunbo509.finefood.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import cn.edu.neosoft.sunbo509.finefood.Bean.CommentBean;
import cn.edu.neosoft.sunbo509.finefood.R;

/**
 * Created by 小博 on 2017/11/3.
 */

public class CommentAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<CommentBean>list;
    private LayoutInflater layoutInflater;

    public CommentAdapter(Context context) {
        this.context=context;
        layoutInflater = LayoutInflater.from(context);
    }
    public void setList(List<CommentBean> list){
        this.list=list;
        notifyDataSetChanged();
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
       final CommentBean bean=list.get(position);
        ViewHolder viewHolder=(CommentAdapter.ViewHolder) holder;
        if(bean==null)
            return;
        viewHolder.tv_username.setText(bean.getUsername());
        viewHolder.tv_content.setText(bean.getContent());
        viewHolder.tv_commenttime.setText(bean.getComment_time());
    }
    @Override
    public int getItemCount() {
        if (list==null)
            return 0;
        else
            return list.size();
    }

    public  class  ViewHolder extends RecyclerView.ViewHolder{
         private TextView tv_username,tv_commenttime,tv_content;
        public ViewHolder(View itemView) {
            super(itemView);
            tv_username=(TextView)itemView.findViewById(R.id.tv_username);
            tv_commenttime=(TextView)itemView.findViewById(R.id.tv_commenttime);
            tv_content=(TextView)itemView.findViewById(R.id.tv_content);
        }
    }

}
